package com.example.cymjoe.huaweishopping.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.cymjoe.huaweishopping.R;
import com.example.cymjoe.huaweishopping.bean.SYGridBean;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by cymjoe on 2016/12/5.
 */
public class GridView_ShouYeAdapter extends BaseAdapter {
    private List<SYGridBean.DataBean.WindowsListBean> data;
    private Context context;

    public GridView_ShouYeAdapter(List<SYGridBean.DataBean.WindowsListBean> data, Context context) {
        this.data = data;
        this.context = context;
    }

    @Override
    public int getCount() {
        return data != null ? data.size() : 0;
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.shouye_gridview01_item, parent, false);
            viewHolder.t1 = (TextView) convertView.findViewById(R.id.windowName);
            viewHolder.t2 = (TextView) convertView.findViewById(R.id.microPromWord);
            viewHolder.img01 = (ImageView) convertView.findViewById(R.id.img);
            convertView.setTag(viewHolder);


        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        SYGridBean.DataBean.WindowsListBean bean = data.get(position);
        if (bean != null) {
            viewHolder.t1.setText(bean.getWindowName());
            viewHolder.t2.setText(bean.getMicroPromWord());
            Picasso.with(context).load(bean.getWindowPicUrl()).error(R.mipmap.ic_launcher).placeholder(R.mipmap.ic_launcher).into(viewHolder.img01);

        }
        return convertView;
    }

    class ViewHolder {
        TextView t1, t2;
        ImageView img01;
    }
}
